﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections;

namespace InpValidator
{
	public abstract class ValidatorService : DependencyObject
	{
		public static ValidatorBase GetValidator(DependencyObject obj)
		{
			return (ValidatorBase)obj.GetValue(ValidatorProperty);
		}

		public static void SetValidator(DependencyObject obj, ValidatorBase value)
		{
			obj.SetValue(ValidatorProperty, value);
		}

		// Using a DependencyProperty as the backing store for Validator.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ValidatorProperty =
			DependencyProperty.RegisterAttached("Validator", typeof(ValidatorBase), typeof(ValidatorService), new PropertyMetadata(ValidatorsPropertyChangedCallback));

		private static void ValidatorsPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
            var v = e.NewValue as ValidatorBase;
            if (v.InitHandlerExist == false)
            {
                System.Diagnostics.Debug.WriteLine("Валидатор не имеет подписчика на событие Init");
                throw new Exception("Валидатор не имеет подписчика на событие Init");
            }
			v.Initialize(d as Control);
            v.Manager.Register(v);
		}
	}
}
